<template>
  <div>
    <input v-model.number="num1" />
    <input v-model.number="num2" />
    <div>两个数之和为{{ result }}</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      num1: 0,
      num2: 0,
      result: 0,
    }
  },
  methods: {
//    sum(){
//      this.result = this.num1 + this.num2
//    }
  },
  watch: {
   num1(){
        this.result = this.num1 + this.num2
        //sum()
    },
    num2(){
        this.result = this.num1 + this.num2
        //sum()
    }
  },
}
</script>

<style>

</style>